<?php
	include dirname(dirname(__FILE__))."/s_user-manage/s_user-verify.php";
	include dirname(__FILE__)."/function.php";
	$ret=getPlaceApplyTable();
?>
<html>
	<head>
		<title>场地申请</title>
		<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php';?>
		<script src="../../js/jquery.ui.widget.js"></script>
		<script src="../../js/jquery.iframe-transport.js"></script>
		<script src="../../js/jquery.fileupload.js"></script>
		<script type="text/javascript">
		$(document).ready(function(){
			$("#accessory").fileupload({
			    url:"ajax/accessory-upload.php",//文件上传地址，当然也可以直接写在input的data-url属性内
			    formData:{},//如果需要额外添加参数可以在这里添加
			    done:function(e,result){
			        //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
			        //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
			        //返回的数据在result.result中，假设我们服务器返回了一个json对象
			    	var json=JSON.parse(result.result);
			    	 if(typeof(json.error) != 'undefined'){
		                    if(json.error != ''){
		                        alert(json.error);
		                    }else{
			                    alert("上传成功");
		                    	$("#storeName").attr("value",json.storeName);
		                    	 $("#upload-div").hide();

		                    }
		                }
			    }
	
			});	
			$("button.apply").click(function(){
				$(".apply").not(this).addClass("disabled");
				$(this).html("选中");
				$result=$.trim($(this).val());
				$("#result").val($result);
				
			});
			$("#submit-btn").click(function(){
				var flag=true;
				var result=$.trim($("#result").val());
				var storeName=$.trim($("#storeName").val());
				if(result==''||result==null){
					alert("请选择时间");
					flag=false;
				}
				if(storeName==""||storeName==null){
					alert("请提交材料");
					flag=false;
				}
				if(flag){
					$("#place-apply-form").submit();
				}
				
				
			});
			
		
		});
		</script>
	</head>
	<body>
	
	<div class="container">	
			<table class="table table-striped table-bordered table-hover table-condensed default-table">
			  <tr>
			  	<th>申请情况</th>
			  	<th>8:00~10:00</th>
			  	<th>10:00~12:00</th>
			  	<th>12:00~14:00</th>
			  	<th>14:00~16:00</th>
			  	<th>16:00~18:00</th>
			  	<th>18:00~20:00</th>
			  	<th>20:00~22:00</th>
			  </tr>
			  
			  	<?php
			  	$i=0; 
			  	while ($row=mysql_fetch_array($ret))
			  	{	echo "<tr>";
			  		
			 	 	echo "<th>".$row["date"]."</th>";
			  		$arr=json_decode($row["table_content"],true);
			  		
			  		foreach ($arr as $key => $value){
						$status=isApplyOrNot($_SESSION["s_user_id"], $row["date"], $key);
						if ($status) {
							if($status==1){
								echo "<th>".'<button class="btn btn-default disabled" >审核中</button>'."</th>";
							}
							if ($status==2) {
								echo "<th>".'<button class="btn btn-default disabled" >成功申请</button>'."</th>";
							}
							if ($status==3) {
								echo "<th>".'<button class="btn btn-default disabled" >申请拒绝</button>'."</th>";
							}
					

						}else{
						if ($i==0||$i==1) {
							if($value==0) {
								echo "<th>".'<button class="btn btn-primary disabled" >截止申请</button>'."</th>";
							}
							if ($value>0) {
								echo "<th>".'<button class="btn btn-default disabled" >已被申请</button>'."</th>";
							}
						
						}else {
					
					
						if($value==0) {
							echo "<th>".'<button class="btn btn-primary apply" value='.'"'.$i.','.$key.'"'.'>申请</button>'."</th>";
						}
						if ($value>0) {
							echo "<th>".'<button class="btn btn-default disabled" >已被申请</button>'."</th>";
						}
						
						}
			  		}	
			  		}						  					  		
			  		echo "</tr>";
			  		$i++;
			  	}?>
			 
			</table>
			<div class="form-horizontal col-md-offset-3" id="upload-div">
				 
			<div class="form-group" >
				    <label for="accessory" class="col-sm-2 control-label">材料上传</label>
				    <div class="col-sm-4">
				      <input  type="file" name="accessory" class="form-control normal-input" id="accessory">
				    </div>
			</div>	
				
				 
			</div>
			
			 <form class="form-horizontal col-md-offset-3" id="place-apply-form" role="form" method="post" action="apply.php">
			 
			 
			  <div class="form-group">
			    <div class="col-sm-offset-2 col-sm-10">
			      <input class="btn btn-primary" id="submit-btn" type="button" value="确认申请">
			    </div>
			  </div>
			  <input name="submited" type="hidden" value="1">
			  <input name="result" id="result" type="hidden" value=""/>
			  <input name="storeName" id="storeName" type="hidden" value=""/>
			</form>
	</div>	
	
	</body>
</html>